/**
 * log工具类
 * 
 * @author zijing.zhang
 */
(function($ns) {

	/**
	 * 定义全局log对象
	 */
	window.log = Qadmin.FW.Log;

	$ns.level = [ "debug", "info", "warn", "error", "none" ];
	$ns.defaultLevel = 0; // level index

	$ns.debug = function() {
		this.print(0, arguments);
	};

	$ns.info = function() {
		this.print(1, arguments);
	};

	$ns.warn = function() {
		this.print(2, arguments);
	};

	$ns.error = function() {
		this.print(3, arguments);
	};

	$ns.print = function(level, arr) {
		var datetime = (new Date()).toLocaleDateString() + " "
				+ (new Date()).toLocaleTimeString();
		if (level >= this.defaultLevel) {
			if (window.console) {
				try {
					switch (level) {
					case 0:
						console.debug("[ DEBUG - " + datetime + "] : ", arr);
						break;
					case 1:
						console.info("[ INFO - " + datetime + "] : ", arr);
						break;
					case 2:
						console.warn("[ WARN - " + datetime + "] : ", arr);
						break;
					case 3:
						console.error("[ ERROR - " + datetime + "] : ", arr);
					}
				} catch (e) {
					console.log("console error!", e);
				}
			} else {
				// ie
				// todo

			}
		}
	};
})(using("Qadmin.FW.Log"));